import { defineStore } from 'pinia'
import { ref } from 'vue'
import {
  getSortListService,
  addSortService,
  updateSortService,
  deleteSortService
} from '@/api/sort'

export const useSortStore = defineStore(
  'sort',
  () => {
    const sort = ref([])
    const getSortList = async () => {
      const res = await getSortListService()
      sort.value = res.data
      console.log(sort.value)
    }
    const addSort = (obj) => {
      return addSortService(obj)
    }
    const updateSort = (obj) => {
      return updateSortService(obj)
    }
    const deleteSort = (id) => {
      return deleteSortService(id)
    }
    return {
      sort,
      getSortList,
      addSort,
      updateSort,
      deleteSort
    }
  },
  {
    persist: true
  }
)
